package com.aotain.oframework.util;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * A special implementation of {@link java.util.LinkedHashMap} to provide
 * LRU functionality.
 * @author Jacob.cw.Zhang@gmail.com
 */
public class LRUMap<K,V> extends LinkedHashMap<K,V> {

    private int maxCapacity;

    public LRUMap(int maxCapacity) {
        super(maxCapacity, 1.0f, true);
        this.maxCapacity = maxCapacity;        
    }

    @Override
	protected boolean removeEldestEntry(Map.Entry eldest) {
        return (size() > maxCapacity);   
    }
}
